package io.renren.modules.business.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.business.entity.EDepartmentEntity;
import io.renren.modules.business.service.EDepartmentService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 部门表
 */
@RestController
@RequestMapping("/business/edepartment")
public class EDepartmentController {

    @Autowired
    private EDepartmentService eDepartmentService;

    /**
     * 根据部门编号/部门名称查询部门信息
     * @param departmentId 部门编号
     * @param departmentName 部门名称
     * @return
     */
    @ResponseBody
    @GetMapping("/queryDepartment")
    public R queryDepartment(@RequestParam(value = "departmentId", required = false) Long departmentId,
                             @RequestParam(value = "departmentName",required = false) String departmentName,
                             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        HashMap<String, Object> resultMap = new HashMap<>();
        resultMap.put("content", eDepartmentService.queryDepartment(pageNum, pageSize, departmentId, departmentName));
        return R.ok(resultMap);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = eDepartmentService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{departmentId}")
    public R info(@PathVariable("departmentId") Long departmentId){
		EDepartmentEntity eDepartment = eDepartmentService.getById(departmentId);
        return R.ok().put("eDepartment", eDepartment);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody EDepartmentEntity eDepartment){
		eDepartmentService.save(eDepartment);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody EDepartmentEntity eDepartment){
		eDepartmentService.updateById(eDepartment);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestParam("departmentId") Long departmentId){
		eDepartmentService.removeById(departmentId);
        return R.ok();
    }

}
